<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import = "jdbc.*" %>
<%@ page import = "java.util.*" %>

<!DOCTYPE html>
<html lang="en">
     <head>
     <title>课程</title>
     <meta charset="utf-8">
     <meta name = "format-detection" content = "telephone=no" />
     <link rel="icon" href="images/favicon.ico" type="image/x-icon">
     <link rel="stylesheet" href="css/style.css">
     <link rel="stylesheet" href="css/font-awesome.min.css">
     <link rel="stylesheet" href="css/stuck.css">
     <link rel="stylesheet" href="css/contact-form.css" media="screen">
     <script src="js/jquery-1.11.1.min.js"></script>
     <script src="js/jquery-migrate-1.2.1.js"></script>
     <script src="js/jquery.easing.1.3.js"></script>
     <script src="js/jquery.ui.totop.js"></script>
     <script src="js/jquery.equalheights.js"></script>
	 <script src="js/script.js"></script>
     <script src="js/superfish.js"></script>
     <script src="js/jquery.mobilemenu.js"></script>
     <script src="js/tmStickUp.js"></script>
     <script src="js/TMForm.js"></script>
     <script src="js/modal.js"></script> 
     <script src="js/sForm.js"></script>
     <link rel="stylesheet" href="css/jquery.fancybox-1.3.4.css">
     <link rel="stylesheet" href="css/sForm.css">
     <script src="js/jquery.fancybox-1.3.4.js"></script>
     <script src="js/sForm.js"></script>
     </head>
     <body>
     
     
	<%@ include file = "./header.jsp" %>
<!--======= Content ================================-->
<div class="content contact" style = "background: antiquewhite;">
	<div class="container">
	    <h3 style="font-family: '微软雅黑';">
        <% 
        boolean valid = true;
        String st = request.getParameter("searchType");
        if (request.getParameter("uemail") != null) {
        	valid = false;
        	email_status = request.getParameter("uemail");
        	user_info = new JdbcDao().getAllPersonalInfo(email_status);
        }
        if (email_status != null) {
        	if (st == null)
        		out.print(email_status + "<br>课程列表");
        	if ("mine".equals(st))
        		out.print(email_status + "<br>我的课程");
        	if ("searchByName".equals(st))
        		out.print(email_status + "<br>名称搜索");
        	if ("searchByNnumber".equals(st))
        		out.print(email_status + "<br>课程号搜索");
        	if ("showl".equals(st))
        		out.print(email_status + "<br>最近课程");
        } else
        	out.print("对不起，请登陆后查看");
        %>
        </h3>
		<div class = "forbidden_hide">
		<%		
		String type = request.getParameter("searchType");		

		JdbcDao mysql = new JdbcDao();
		List<HashMap<String, String>> listhm = null;
		
		if (type == null) {
			listhm = mysql.getClassList();
		} else if (type.equals("mine")) {
			listhm = mysql.getMyClassList(email_status);
		} else if (type.equals("searchByName")) {
			String searchContent = request.getParameter("content");
			listhm = mysql.searchClassByName(searchContent);
		} else if (type.equals("searchByNnumber")) {
			String searchContent = request.getParameter("content");
			listhm = mysql.searchClassByNumber(searchContent);
		} else if (type.equals("showl")) {
			String searchContent = request.getParameter("content");
			listhm = mysql.getClassInTwoDay(email_status);
		} else {
			listhm = mysql.getClassList();
		}
		%>
		<div class = "cblock" style="display:none">
			<h4>查找课程</h4>
			<form action="classlist.jsp" method="GET">
				<div>搜索选项：
				<select name = "searchType" style = "font-family : '微软雅黑'">
				<option value = "mine">我的课程</option>
				<option value = "searchByName">按名称搜索</option>
				<option value = "searchByNnumber">按课程号搜索</option>
				</select>
				</div>
				<div>搜索内容: <input name = "搜索内容" type="text"/></div>
				<input type="submit" value="查找课程" />
			</form>
		</div>
		<div class = "cblock" style="display:none">
			<h4>选课</h4>
			<form action="chooseclass.jsp" method="GET">
				<div>email : <input name = "email" type="text"/></div>
				<div>课程号 : <input name = "classNumber" type="text"/></div>
				<input type="submit" value="选课" />
			</form>	
		</div>
		<div class = "cblock" style="display:none">
			<h4>退课</h4>
			<form action="deluserclass.jsp" method="GET">
				<div>email : <input name = "email" type="text"/></div>
				<div>课程号 : <input name = "classNumber" type="text"/></div>
				<input type="submit" value="退课" />
			</form>
		</div>
		<div class = "cblock" style="display:none">
			<div class = "user_hide forbidden_hide invalid_hide">
			<br>
			<h4>删除课程</h4>
			<form action="delclass.jsp" method="GET">
				<div>课程号 : <input name = "classNumber" type="text"/></div>
				<input type="submit" value="删除课程" />
			</form>
		</div>
		<div class = "cblock" style="display:none">
			<h4>新建课程</h4><br>
			<form action="newclass.jsp" method="GET">
				<input type="submit" value="New Class" />
			</form>	
		</div>
			</div>
						
		<div class="tab" style="width:100%;margin-left:0px;margin-right:0px;" id="table_sy">
		        
		     
		     <table id = "classtable" border="4" cellpadding="2" cellspacing="2">
				  <tr class="trr1">
		                         <td style="width:5%"><div align="center"><span class="trunk">课程号</span></div></td>
								 <td style="width:8%"><div align="center"><span class="trunk">课程名</span></div></td>
		                         <td style="width:4%"><div align="center"><span class="trunk" id="xf_sy">学分</span></div></td>
		                         <td style="width:5%"><div align="center"><span class="trunk">主讲教师</span></div></td>
								 <td style="width:5%"><div align="center"><span class="bkskrl">本科生课容量</span></div></td>
		                     	 <td style="width:12%"><div align="center" style=""><span class="trunk">上课时间</span></div></td>
					    		 <td style="width:4%"><div align="center"><span class="trunk">已选人数</span></div></td>
				 </tr>
				 
				 <%
				 int len = listhm.size();				 
				 for (int i = 0; i < len; ++i) {		 
				 	HashMap<String, String> classHM = listhm.get(i);
				 
				 %>
					
		         <tr class="trr2">
								 <td><div align="center"><span><% out.println(classHM.get("number")); %></span></div></td>
								
		                         <td><div align="center"><span class="trunk"><% 
			                     out.print("<a href='article.jsp?aid=" + classHM.get("number") + "'>");
		                         out.print(classHM.get("name")); 
		                         out.print("</a>");
		                         if ("user".equals(ppt) || "admin".equals(ppt)) {
		                        	 out.print("<a class='opsbut iframe' href='chooseclass.jsp?email=" + email_status + 
		                        			 "&classNumber=" + classHM.get("number") + "'>[选课]</a>");
		                        	 out.print("<a class='opsbut iframe'  href='deluserclass.jsp?email=" + email_status + 
		                        			 "&classNumber=" + classHM.get("number") + "'>[退课]</a>");
		                        	 if ("admin".equals(ppt))
		                        	 	out.print("<a class='opsbut iframe'  href='delclass.jsp?email=" + email_status + 
		                        			 "&classNumber=" + classHM.get("number") + "'>[删除]</a>");
		                         }
		                         %></span></div></td>
		 					
								 <td><div align="center"><span ><% out.println(classHM.get("credit")); %></span></div></td>
								
								 <td><div align="center"><span class="trunk"><% out.println(classHM.get("teacher")); %></span></div></td>   
		 					
								 <td><div align="center"><span ><% out.println(classHM.get("numlimit")); %></span></div></td>
								 <td><div align="center"><span class="trunk"><% out.println(classHM.get("classdate")); %></span></div></td>
		
				    			 <td><div align="center"><span class="trunk"><% out.println(classHM.get("tempnum")); %></span></div></td>
		
				   </tr>
				   <%
				 	}
			   
				   %>
		  	</table>
		</div>
		</div>
	</div>
</div>


<!--======= Footer =================================-->


<%@ include file = "./footer.jsp" %>

</body>
</html>